package com.blog.controller;

import com.blog.common.CommonRespDto;
import com.blog.common.RespBean;
import com.blog.seckill.goods.ProductSku;
import com.blog.service.ProductSkuBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ProductSkuBaseController
 * @Destription ProductSku基础：增删改查
 * @Author 天堂小野花
 * @Date 2025/8/19  19:16
 * @Version 1.0
 */
@RestController
@RequestMapping("/productSku")
public class ProductSkuBaseController {
    @Autowired
    ProductSkuBaseService productSkuBaseService;
    @GetMapping("/base/selectProductSkuById/{rid}")
    public CommonRespDto selectProductSkuById(@PathVariable Integer rid){
        return CommonRespDto.success(productSkuBaseService.selectProductSkuById(rid.longValue()));
    }

    @PostMapping("/base/insertProductSku")
    public RespBean insertProductSku(@RequestBody ProductSku productSku){
        if(productSkuBaseService.insertProductSku(productSku) == 1 ){
            return RespBean.ok("添加成功");
        }
        return RespBean.error("添加失败");
    }
    @DeleteMapping("/base/deleteProductSku/{rid}")
    public RespBean deleteProductSkuById(@PathVariable Integer rid){
        if(productSkuBaseService.deleteProductSkuById(rid.longValue()) == 1){
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }
    @PutMapping("/base/updateProductSku")
    public RespBean updateProductSku(@RequestBody ProductSku productSku){

        if(productSkuBaseService.updateProductSku(productSku) == 1){
            return RespBean.ok("更新成功");
        }
        return RespBean.error("更新失败");
    }
}
